<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_vip\Entity\ShusyVip;

/**
 * @OA\Schema(
 *   schema="VipItem",
 *   type="object",
 *   description="VipItem"
 * )
 */
class VipItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_vip';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyVip) {
      $value = [
        /**
         * @OA\Property(
         *   property="id",
         *   type="integer",
         *   description="ID",
         * ),
         */
        'id' => (int) $this->entity->id,
        /**
         * @OA\Property(
         *   property="name",
         *   type="string",
         *   description="VIP名",
         * ),
         */
        'name' => (string) $this->entity->name,
        /**
         * @OA\Property(
         *   property="rebate",
         *   type="number",
         *   description="折扣 0-10",
         * ),
         */
        'rebate' => ($this->entity->rebate / 1000),
        /**
         * @OA\Property(
         *   property="amount",
         *   type="number",
         *   description="累计消费",
         * ),
         */
        'amount' => $this->convertYuan($this->entity->amount),
      ];
      $this->merge($value);
    }
  }

  protected function getValidity(int $validity) {
    return ceil($validity / (24 * 60 * 60)) . '天';
  }
}
